/*
PearReview - The peer review assistant.
Copyright (C) 2009  Dimitrij Pankratz, Anton Musichin
http://www.pearreview.com, info@pearreview.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

package com.pearreview.moderatorplugin;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.swing.*;

import com.pearreview.ui.*;
import com.pearreview.ui.datepicker.DatePicker;
import com.pearreview.ui.slidebox.MeetingSlideBoxPanel;
import com.pearreview.ui.slidebox.SlideBoxPanel;
import com.pearreview.application.Messages;
import com.pearreview.util.review.Meeting;

public class MeetingsPanel extends PearPanel implements ModeratorPanel {
	private static final long serialVersionUID = 9123158084318635657L;
	
	public static final long DEFAULT_MEETING_DURUATION = 2 * 60 * 60 * 1000;
	
	private FormLabel meetingDateLabel;
	private DateSpinner meetingDate;
	private FormLabel meetingStartLabel;
	private TimeSpinner meetingStart;
	private FormLabel meetingEndLabel;
	private TimeSpinner meetingEnd;
	private FormLabel meetingLocationLabel;
	private CompletableJTextField meetingLocation;
	private FormLabel meetingCommentsLabel;
	private JScrollPane scrollPaneMeetingComments;
	private FadingTextArea meetingComments;
	private JButton datePickerBtn;
	private JButton addMeetingBtn;
	
	private FormLabel editMeetingDateLabel;
	private DateSpinner editMeetingDate;
	private FormLabel editMeetingStartLabel;
	private TimeSpinner editMeetingStart;
	private FormLabel editMeetingEndLabel;
	private TimeSpinner editMeetingEnd;
	private FormLabel editMeetingLocationLabel;
	private CompletableJTextField editMeetingLocation;
	private FormLabel editMeetingCommentsLabel;
	private JScrollPane editScrollPaneMeetingComments;
	private FadingTextArea editMeetingComments;
	private JButton editDatePickerBtn;
	private JButton saveMeetingBtn;
	private JButton abortMeetingBtn;
	
	private MeetingSlideBoxPanel slideList;
	private SlideBoxPanel.RemoveConfirmer removeConfirmer = 
			new RemoveConfirmer();
	private JPanel formPanel;
	private JPanel newFormPanel;
	private JPanel editFormPanel;
	private GroupLayout layout;
	private HeadingLabel headingLabel;
	private Meeting editMeeting;
	
	private BottomButtonPanel bottom;
	
	public MeetingsPanel() {
		initComponents();
	}
	
	/**
	 * Sets list of meetings
	 * @param meetings meetings to set
	 */
	public void setMeetings(List<Meeting> meetings) {
		slideList.clearList();
		
		if(meetings != null)
			slideList.setElements(meetings);
	}
	
	@Override
	public boolean isValidForm() {
		return slideList.getListSize() > 0;
	}
	
	/**
	 * Returns list of meetings
	 * @return meetings
	 */
	public List<Meeting> getMeetings() {
		int count = slideList.getListSize();
		
		if(count == 0)
			return null;		
		
		List<Meeting> lst = new ArrayList<Meeting>();
		
		for(int i = 0 ; i < count ; i++) {
			Meeting meeting = slideList.getListElement(i);
			
			if(meeting.getPlannedLocation() == null)
				meeting.setPlannedLocation("");
			
			if(meeting.getComments() == null)
				meeting.setComments("");
			
			lst.add(meeting);
		}
		
		return lst;
	}
	
	private void initComponents() {
		
		meetingDateLabel = new FormLabel(
				Messages.getString("PearReview.Moderator.meetings.date"));
		meetingDate = new DateSpinner();
		meetingStartLabel = new FormLabel(
				Messages.getString("PearReview.Moderator.meetings.start"));
		meetingStart = new TimeSpinner();
		meetingEndLabel = new FormLabel(
				Messages.getString("PearReview.Moderator.meetings.end"));
		meetingEnd = new TimeSpinner(new Date(
				meetingStart.getDate().getTime() + DEFAULT_MEETING_DURUATION));
		meetingLocationLabel = new FormLabel(
				Messages.getString("PearReview.Moderator.meetings.place"));
		meetingLocation = new CompletableJTextField();
		meetingCommentsLabel = new FormLabel(
				Messages.getString("PearReview.Moderator.meetings.comments"));
		scrollPaneMeetingComments = new JScrollPane();
		meetingComments = new FadingTextArea();
		datePickerBtn = new JButton();
				//Messages.getString("PearReview.Moderator.meetings.choose"));
		addMeetingBtn = new JButton();
		
		
		editMeetingDateLabel = new FormLabel(
				Messages.getString("PearReview.Moderator.meetings.date"));
		editMeetingDate = new DateSpinner();
		editMeetingStartLabel = new FormLabel(
				Messages.getString("PearReview.Moderator.meetings.start"));
		editMeetingStart = new TimeSpinner();
		editMeetingEndLabel = new FormLabel(
				Messages.getString("PearReview.Moderator.meetings.end"));
		editMeetingEnd = new TimeSpinner();
		editMeetingLocationLabel = new FormLabel(
				Messages.getString("PearReview.Moderator.meetings.place"));
		editMeetingLocation = new CompletableJTextField();
		editMeetingCommentsLabel = new FormLabel(
				Messages.getString("PearReview.Moderator.meetings.comments"));
		editScrollPaneMeetingComments = new JScrollPane();
		editMeetingComments = new FadingTextArea();
		editDatePickerBtn = new JButton();
				//Messages.getString("PearReview.Moderator.meetings.choose"));
		saveMeetingBtn = new JButton();
		abortMeetingBtn = new JButton();
		
		
		ActionListener dateAction = new ActionListener() { 
			@Override
			public void actionPerformed(ActionEvent e) {
				JPopupMenu datePicker = new DatePicker(meetingDate);
				datePicker.show(datePickerBtn, 0, datePickerBtn.getHeight());
				//datePicker.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
			}
    	};
    	
    	datePickerBtn.addActionListener(dateAction);		
		
		this.setLayout(new BorderLayout());
		this.setPreferredSize(new Dimension(680,400));
		
		setBackground(new Color(214, 214, 214));
		

		//======== scrollPaneReviewComments ========
		scrollPaneMeetingComments.setViewportView(meetingComments);
		
		//======== datePickerBtn ========
		ImageIcon ico = getResourceIcon("date.png");
		datePickerBtn.setIcon(ico);
		datePickerBtn.setToolTipText(
				Messages.getString("PearReview.Moderator.meetings.choose"));
		datePickerBtn.setMargin(new Insets(0,0,0,0));
		
		//======== addMeetingBtn ========
		addMeetingBtn.setAction(new AddNewMeetingAction());
		addMeetingBtn.setText(
				Messages.getString("PearReview.Moderator.add_btn"));
		addMeetingBtn.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		newFormPanel = new JPanel();
		
		slideList = new MeetingSlideBoxPanel(new EditMeetingAction());
		slideList.setRemoveConfirmer(removeConfirmer);

		
		
		//======== newMeetingPanel ========
		
		newFormPanel = new JPanel();
		newFormPanel.setOpaque(false);

		GroupLayout newLayout = new GroupLayout(newFormPanel);
		
		newFormPanel.setLayout(newLayout);
		newLayout.setHorizontalGroup(
				newLayout.createParallelGroup()
				.addGroup(newLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(newLayout.createParallelGroup()
						.addGroup(newLayout.createSequentialGroup()
							.addGroup(newLayout.createParallelGroup()
								.addGroup(GroupLayout.Alignment.TRAILING, 
										newLayout.createSequentialGroup()
									.addGroup(newLayout.createParallelGroup()
										.addComponent(meetingDateLabel, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 80,
												GroupLayout.PREFERRED_SIZE)
										.addComponent(meetingStartLabel, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 80, 
												GroupLayout.PREFERRED_SIZE)
										.addComponent(meetingEndLabel, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 80, 
												GroupLayout.PREFERRED_SIZE)
										.addComponent(meetingLocationLabel, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 80, 
												GroupLayout.PREFERRED_SIZE)
										.addComponent(meetingCommentsLabel, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 80, 
												GroupLayout.PREFERRED_SIZE))
									.addGap(57, 57, 57)
									.addGroup(newLayout.createParallelGroup(
											GroupLayout.Alignment.TRAILING)
										.addComponent(addMeetingBtn, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 
												GroupLayout.PREFERRED_SIZE, 
												GroupLayout.PREFERRED_SIZE)
										.addComponent(
												scrollPaneMeetingComments, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 300, 
												GroupLayout.PREFERRED_SIZE)
										.addComponent(meetingLocation, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 300, 
												GroupLayout.PREFERRED_SIZE)
										.addComponent(meetingEnd, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 300, 
												GroupLayout.PREFERRED_SIZE)
										.addComponent(meetingStart, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 
												300, 
												GroupLayout.PREFERRED_SIZE)
										.addGroup(
											newLayout.createSequentialGroup()
											.addComponent(meetingDate, 
													GroupLayout.PREFERRED_SIZE, 
													265, 
													GroupLayout.PREFERRED_SIZE)
											.addGap(10, 10, 10)
											.addComponent(datePickerBtn, 
													GroupLayout.PREFERRED_SIZE, 
													25, 
													GroupLayout.PREFERRED_SIZE)
		))))))));
		
		newLayout.setVerticalGroup(
				newLayout.createParallelGroup()
				.addGroup(
						newLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(newLayout.createParallelGroup(
							GroupLayout.Alignment.BASELINE)
						.addComponent(meetingDateLabel)
						.addComponent(meetingDate, 
								GroupLayout.PREFERRED_SIZE, 
								GroupLayout.DEFAULT_SIZE, 
								GroupLayout.PREFERRED_SIZE)
						.addComponent(datePickerBtn, 
								GroupLayout.PREFERRED_SIZE, 
								GroupLayout.DEFAULT_SIZE, 
								GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(newLayout.createParallelGroup()
						.addComponent(meetingStartLabel)
						.addComponent(meetingStart, 
								GroupLayout.PREFERRED_SIZE, 
								GroupLayout.DEFAULT_SIZE, 
								GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(newLayout.createParallelGroup()
						.addComponent(meetingEndLabel)
						.addComponent(meetingEnd, 
								GroupLayout.PREFERRED_SIZE, 
								GroupLayout.DEFAULT_SIZE, 
								GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(newLayout.createParallelGroup()
						.addComponent(meetingLocationLabel)
						.addComponent(meetingLocation, 
								GroupLayout.PREFERRED_SIZE, 
								GroupLayout.DEFAULT_SIZE, 
								GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(newLayout.createParallelGroup()
						.addComponent(meetingCommentsLabel)
						.addComponent(scrollPaneMeetingComments, 
								GroupLayout.PREFERRED_SIZE, 
								68, 
								GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(newLayout.createParallelGroup()
						.addComponent(addMeetingBtn)))
		);
		
		ActionListener editDateAction = new ActionListener() { 
			@Override
			public void actionPerformed(ActionEvent e) {
				JPopupMenu datePicker = new DatePicker(editMeetingDate);
				datePicker.show(editDatePickerBtn, 
						0, 
						editDatePickerBtn.getHeight());
				//datePicker.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
			}
    	};
    	
    	editDatePickerBtn.addActionListener(editDateAction);		
		

		//======== editScrollPaneReviewComments ========
		editScrollPaneMeetingComments.setViewportView(editMeetingComments);
		
		//======== editDatePickerBtn ========
		editDatePickerBtn.setIcon(ico);
		editDatePickerBtn.setToolTipText(
				Messages.getString("PearReview.Moderator.meetings.choose"));
		editDatePickerBtn.setMargin(new Insets(0,0,0,0));
		
		//======== saveMeetingBtn ========
		saveMeetingBtn.setAction(new EndEditMeetingAction());
		saveMeetingBtn.setText(Messages.getString(
				"PearReview.Moderator.meetings.save"));
		saveMeetingBtn.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		//======== abortMeetingBtn ========
		abortMeetingBtn.setAction(new AbortEditMeetingAction());
		abortMeetingBtn.setText(Messages.getString(
				"PearReview.Moderator.meetings.abort"));
		abortMeetingBtn.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		
		//======== editMeetingPanel ========
		
		editFormPanel = new JPanel();
		editFormPanel.setOpaque(false);

		GroupLayout editLayout = new GroupLayout(editFormPanel);
		
		editFormPanel.setLayout(editLayout);
		editLayout.setHorizontalGroup(
				editLayout.createParallelGroup()
				.addGroup(editLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(editLayout.createParallelGroup()
						.addGroup(editLayout.createSequentialGroup()
							.addGroup(editLayout.createParallelGroup()
								.addGroup(GroupLayout.Alignment.TRAILING, 
										editLayout.createSequentialGroup()
									.addGroup(editLayout.createParallelGroup()
										.addComponent(editMeetingDateLabel, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 
												80, 
												GroupLayout.PREFERRED_SIZE)
										.addComponent(editMeetingStartLabel, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 
												80, 
												GroupLayout.PREFERRED_SIZE)
										.addComponent(editMeetingEndLabel, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 
												80, 
												GroupLayout.PREFERRED_SIZE)
										.addComponent(editMeetingLocationLabel, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 
												80, 
												GroupLayout.PREFERRED_SIZE)
										.addComponent(editMeetingCommentsLabel, 
												GroupLayout.Alignment.LEADING, 
												GroupLayout.DEFAULT_SIZE, 
												80, 
												GroupLayout.PREFERRED_SIZE))
									.addGap(57, 57, 57)
									.addGroup(editLayout.createParallelGroup(
											GroupLayout.Alignment.LEADING)
									.addGroup(
											editLayout.createSequentialGroup()
											.addComponent(saveMeetingBtn)
											.addGap(10)
											.addComponent(abortMeetingBtn))
									.addComponent(
											editScrollPaneMeetingComments, 
											GroupLayout.Alignment.LEADING, 
											GroupLayout.DEFAULT_SIZE, 
											300, 
											GroupLayout.PREFERRED_SIZE)
									.addComponent(
											editMeetingLocation, 
											GroupLayout.Alignment.LEADING, 
											GroupLayout.DEFAULT_SIZE, 
											300, 
											GroupLayout.PREFERRED_SIZE)
									.addComponent(editMeetingEnd, 
											GroupLayout.Alignment.LEADING, 
											GroupLayout.DEFAULT_SIZE, 
											300, 
											GroupLayout.PREFERRED_SIZE)
									.addComponent(editMeetingStart, 
											GroupLayout.Alignment.LEADING, 
											GroupLayout.DEFAULT_SIZE, 
											300, 
											GroupLayout.PREFERRED_SIZE)
									.addGroup(
											editLayout.createSequentialGroup()
											.addComponent(editMeetingDate, 
													GroupLayout.PREFERRED_SIZE, 
													265, 
													GroupLayout.PREFERRED_SIZE)
											.addGap(10, 10, 10)
											.addComponent(
													editDatePickerBtn, 
													GroupLayout.PREFERRED_SIZE,
													25,
													GroupLayout.PREFERRED_SIZE)
		))))))));
		
		editLayout.setVerticalGroup(
				editLayout.createParallelGroup()
				.addGroup(
						editLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(editLayout.createParallelGroup(
							GroupLayout.Alignment.BASELINE)
						.addComponent(editMeetingDateLabel)
						.addComponent(editMeetingDate, 
								GroupLayout.PREFERRED_SIZE, 
								GroupLayout.DEFAULT_SIZE, 
								GroupLayout.PREFERRED_SIZE)
						.addComponent(editDatePickerBtn, 
								GroupLayout.PREFERRED_SIZE, 
								GroupLayout.DEFAULT_SIZE, 
								GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(editLayout.createParallelGroup()
						.addComponent(editMeetingStartLabel)
						.addComponent(editMeetingStart, 
								GroupLayout.PREFERRED_SIZE, 
								GroupLayout.DEFAULT_SIZE, 
								GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(
							LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(editLayout.createParallelGroup()
						.addComponent(editMeetingEndLabel)
						.addComponent(editMeetingEnd, 
								GroupLayout.PREFERRED_SIZE, 
								GroupLayout.DEFAULT_SIZE, 
								GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(editLayout.createParallelGroup()
						.addComponent(editMeetingLocationLabel)
						.addComponent(editMeetingLocation, 
								GroupLayout.PREFERRED_SIZE, 
								GroupLayout.DEFAULT_SIZE, 
								GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(editLayout.createParallelGroup()
						.addComponent(editMeetingCommentsLabel)
						.addComponent(editScrollPaneMeetingComments, 
								GroupLayout.PREFERRED_SIZE, 
								68, 
								GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(editLayout.createParallelGroup()
						.addComponent(abortMeetingBtn)
						.addComponent(saveMeetingBtn)))
		);
		
		
		//======== formPanel ========
		
		formPanel = new JPanel();
		formPanel.setOpaque(false);

		layout = new GroupLayout(formPanel);
		
		initFormPanel(newFormPanel);
		
		formPanel.setPreferredSize(new Dimension(300, 300));
		add(formPanel, BorderLayout.CENTER);
		headingLabel = new HeadingLabel(
				Messages.getString("PearReview.Moderator.tabs.meetings"));
		add(headingLabel, BorderLayout.NORTH);
		
		bottom = new BottomButtonPanel();
		add(bottom, BorderLayout.SOUTH);
	}
	
	private void initFormPanel(JPanel currentFormPanel) {
		formPanel.removeAll();
		formPanel.setLayout(layout);
		layout.setHorizontalGroup(
			layout.createParallelGroup()
				.addGroup(layout.createSequentialGroup()
					//.addContainerGap()
					.addGroup(layout.createParallelGroup()
						.addGroup(layout.createSequentialGroup()
							.addGroup(layout.createParallelGroup()
								.addGroup(
										GroupLayout.Alignment.TRAILING, 
										layout.createSequentialGroup()
									.addGroup(layout.createParallelGroup()
											.addComponent(currentFormPanel))
									.addGap(37, 37, 37)
									.addGroup(layout.createParallelGroup(
											GroupLayout.Alignment.TRAILING)
											.addComponent(slideList, 
													GroupLayout.PREFERRED_SIZE, 
													GroupLayout.DEFAULT_SIZE, 
													Short.MAX_VALUE))
									.addGap(10, 10, 10))))))
								
		);
		layout.setVerticalGroup(
			layout.createParallelGroup()
				.addGroup(layout.createSequentialGroup()
					.addComponent(currentFormPanel))
					.addGroup(layout.createSequentialGroup()
							.addContainerGap()
							.addComponent(slideList)
							.addContainerGap())
		);
	}
	
	private Meeting getMeetingNewForm() {
		Meeting meeting = new Meeting();
		
		Calendar calDate = Calendar.getInstance();
		calDate.setTime(meetingDate.getDate());
		meeting.setPlannedDate(calDate);
		
		Calendar calStart = Calendar.getInstance();
		calStart.setTime(meetingStart.getDate());
		meeting.setPlannedStart(calStart);
		
		Calendar calEnd = Calendar.getInstance();
		calEnd.setTime(meetingEnd.getDate());
		meeting.setPlannedEnd(calEnd);
		
		meetingLocation.addCompletion(meetingLocation.getText());
		editMeetingLocation.addCompletion(meetingLocation.getText());
		meeting.setPlannedLocation(meetingLocation.getText());
		meetingLocation.setText(null);
		
		meeting.setComments(meetingComments.getText());
		meetingComments.setText(null);
		
		return meeting;
	}
	
	private Meeting getMeetingEditForm() {
		Meeting meeting = editMeeting;
		
		Calendar calDate = Calendar.getInstance();
		calDate.setTime(editMeetingDate.getDate());
		meeting.setPlannedDate(calDate);
		
		Calendar calStart = Calendar.getInstance();
		calStart.setTime(editMeetingStart.getDate());
		meeting.setPlannedStart(calStart);
		
		Calendar calEnd = Calendar.getInstance();
		calEnd.setTime(editMeetingEnd.getDate());
		meeting.setPlannedEnd(calEnd);
		
		meetingLocation.addCompletion(editMeetingLocation.getText());
		editMeetingLocation.addCompletion(editMeetingLocation.getText());
		meeting.setPlannedLocation(editMeetingLocation.getText());
		editMeetingLocation.setText(null);
		
		meeting.setComments(editMeetingComments.getText());
		editMeetingComments.setText(null);
		
		return meeting;
	}
	
	private void setEditForm(Meeting meeting) {
		
		editMeetingDate.setDate(meeting.getPlannedDate().getTime());
		
		editMeetingStart.setDate(meeting.getPlannedStart().getTime());
		
		editMeetingEnd.setDate(meeting.getPlannedEnd().getTime());
		
		editMeetingLocation.setText(meeting.getPlannedLocation());
		
		editMeetingComments.setText(meeting.getComments());
	}
	
	/**
	 * Returns an resource icon
	 * @param name name of icon
	 * @return
	 */
	private ImageIcon getResourceIcon(String name) {
		return new ImageIcon(getClass().getResource("images/" + name));
	}
	
	private class AddNewMeetingAction extends AbstractAction {
		private static final long serialVersionUID = -5311334473554149230L;
		@Override
		public void actionPerformed(ActionEvent e) {
			slideList.addToList(getMeetingNewForm());
		}
	}
	
	private class EditMeetingAction extends AbstractAction {
		private static final long serialVersionUID = -2828507055256361858L;
		@Override
		public void actionPerformed(ActionEvent e) {
			Meeting meeting = (Meeting)e.getSource();
			editMeeting = meeting;
			
			//save to editMeeting
			/*
			editMeeting = new Meeting();
			editMeeting.setCanceled(meeting.getCanceled());
			editMeeting.setComments(meeting.getComments());
			editMeeting.setPlannedDate(meeting.getPlannedDate());
			editMeeting.setPlannedEnd(meeting.getPlannedEnd());
			editMeeting.setPlannedLocation(meeting.getPlannedLocation());
			editMeeting.setPlannedStart(meeting.getPlannedStart());
			editMeeting.setProtocol(meeting.getProtocol());
			*/
			
			slideList.startEdit(meeting);
			
			setEditForm(meeting);
			initFormPanel(editFormPanel);
			headingLabel.setCaption(
					Messages.getString("PearReview.Moderator.tabs.meetings") +
					" - " + Messages.getString(
						"PearReview.Moderator.meetings.edit_heading"), true);
		}
	}
	
	private class EndEditMeetingAction extends AbstractAction {
		private static final long serialVersionUID = 3284167201738164693L;
		@Override
		public void actionPerformed(ActionEvent e) {
			
			slideList.endEdit(getMeetingEditForm());
			initFormPanel(newFormPanel);
			headingLabel.setCaption(
					Messages.getString("PearReview.Moderator.tabs.meetings"), 
					false);
		}
	}
	
	private class AbortEditMeetingAction extends AbstractAction {
		private static final long serialVersionUID = -5711631210176334832L;

		@Override
		public void actionPerformed(ActionEvent e) {
			
			slideList.abortEdit();
			initFormPanel(newFormPanel);
			headingLabel.setCaption(
					Messages.getString("PearReview.Moderator.tabs.meetings"), 
					false);
		}
	}
	
	private class RemoveConfirmer implements Serializable,
			SlideBoxPanel.RemoveConfirmer {
		private static final long serialVersionUID = -4445210152359372812L;
		@Override
		public boolean canRemove(SlideBoxPanel<?> panel, Object element,
				int index) {
			if(element instanceof Meeting) {
				Meeting meeting = (Meeting) element;
				return canRemove(meeting);
			}
			return true;
		}
		private boolean canRemove(Meeting meeting) {
			// TODO meeting remove confirmer
			return meeting.getProtocol() == null;
		}
	}

	@Override
	public String getHint() {
		return Messages.getString("PearReview.hint.moderator.meetings");
	}

	@Override
	public String getErrorMessage() {
		return Messages.getString("PearReview.Moderator.tabs.meetings_error");
	}

	@Override
	public void setNextViewAction(Action action) {
		bottom.setNextViewAction(action);
	}

	@Override
	public void setPreviousViewAction(Action action) {
		bottom.setPreviousViewAction(action);
	}

}